﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Profile;
using umbraco;
using CommerceForUmbraco.profile;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.propertytype;
using Commerce.Common;
using System.Text;

namespace CommerceForUmbraco.usercontrols.usercontrols.commerce
{
    public partial class PWCustomerOrderHistory : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack == false)
            {
                DisplayOrderHistoryForCurrentUser();
            }

        }

        private void DisplayOrderHistoryForCurrentUser()
        {
            Member currentMember = Member.GetCurrentMember();
            if (currentMember == null)
            {
                this.ctrlOrderHistoryHTML.Visible = false;
                this.ctrlErrorFeedbackLabel.Text = "Sorry, you must be signed on in order to view your order history.";
                return;
            }

            OrderCollection orders = OrderController.GetByUser();

            if (orders == null || orders.Count == 0)
            {
                this.ctrlOrderHistoryHTML.Visible = false;
                this.ctrlErrorFeedbackLabel.Text = "You have no record of any completed orders at this time.";
                return;
            }

            StringBuilder sb = new StringBuilder();
            foreach (Order order in orders)
            {
                //sb.Append(order.ToHtml());
                //sb.Append("<hr />");
            }

            //ctrlOrderHistoryHTML.Text = sb.ToString();



            ctrlOrderHistoryGridView.DataSource = orders;
            ctrlOrderHistoryGridView.DataBind();
        }
    }
}